from matplotlib import pyplot as plt

FILENAME = "out{}/munge_{}.txt"
FILES = [2**n for n in range(3, 7)]
COLORS = ((1.0, 0.0, 0.0),
          (0.0, 0.7, 0.0),
          (0.0, 0.0, 1.0),
          (0.2, 0.2, 0.2))

for i, fn in enumerate(FILES):
    x = []
    y = []
    with open(FILENAME.format(1, fn)) as fp:
        lines = fp.readlines()
        for l in lines:
            n, time = l.split('\t')
            x.append(int(n))
            y.append(float(time))
    plt.figure(1)
    plt.subplot(221 + i)
    plt.plot(x, y, '.', color=COLORS[i], markersize=5)
    plt.xticks([i*8 for i in range(9)])
    plt.yticks([i*1000000 for i in range(9)], ["{} M".format(i) for i in range(9)])
    plt.xlim([0, 64])
    plt.title("{}".format(FILES[i]))
    plt.figure(2)
    plt.plot(x, y, '.', color=COLORS[i], markersize=8)

plt.figure(1)
plt.savefig("out1.png")
plt.figure(2)
plt.xticks([i*4 for i in range(17)])
plt.yticks([i*1000000 for i in range(9)], ["{} M".format(i) for i in range(9)])
plt.legend(FILES)
plt.xlim([0, 64])
plt.savefig("out1-all.png")
plt.clf()

for i, fn in enumerate(FILES):
    x = []
    y = []
    with open(FILENAME.format(2, fn)) as fp:
        lines = fp.readlines()
        for l in lines:
            n, time = l.split('\t')
            x.append(int(n))
            y.append(float(time))
    plt.figure(3)
    plt.plot(x, y, '.', color=COLORS[i], markersize=8)

plt.figure(3)
plt.xticks([i*4 for i in range(17)])
plt.ylim([0, 250])
plt.legend(FILES)
plt.xlim([0, 64])
plt.savefig("out2-all.png")
plt.clf()
